package com.cfs.chat.common.config;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: 这个配置类通过实现 WebMvcConfigurer 接口并重写 addResourceHandlers 方法，把URL路径/img/** 映射到服务器文件系统上的 imgPath 目录中，以实现静态资源的访问。
 * @Author: fengwei-lhq
 * @Date: 2024-11-28 10:45
 **/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final String imgPath = new ApplicationHome(getClass()).getSource().getParentFile().toString() + "/img/";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + imgPath);
    }

}
